package com.zhiyou.ex;


import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//全局异常处理器
@Component
public class OperationExceptionResolver {
//public class OperationExceptionResolver implements HandlerExceptionResolver {
//    //日志对象
//    private Logger logger = Logger.getLogger(OperationExceptionResolver.class);
//    @Override
//    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
//        //1.解析出异常类型
//        OperationException operationException = null;
//        if(e instanceof OperationException){
//            //2、如果该异常类型是自定义的操作异常，直接获取异常信息，在错误页面展示
//            operationException = (OperationException)e;
//        }else {
//            //3、如果该异常类型不是自定义的操作异常，构建一个自定义的操作异常类型
//            operationException = new OperationException("系统错误，请联系管理员");
//        }
//
//        //错误信息
//        String errorMessage = operationException.getErrorMessage();
//
//        //记录异常日志
//        logger.error(errorMessage);
//
//        //返回错误页面
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("errorMessage",errorMessage);
//        modelAndView.setViewName("/error");
//        return modelAndView;

//}
}
